import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s1 = scan.nextLine();
        String s2 = scan.nextLine();
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        if (c1.length > c2.length) {
            char[] temp = c1;
            c1 = c2;
            c2 = temp;
        }
        int len1 = c1.length;
        int len2 = c2.length;
        int maxLen = 0;
        int startIndex = 0;
        int[][] dp = new int[len1 + 1][len2 + 1];
        for (int i = 0; i < len1; i++) {
            for (int j = 0; j < len2; j++) {
                if (c1[i] == c2[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                    if (dp[i + 1][j + 1] > maxLen) {
                        maxLen = dp[i + 1][j + 1];
                        startIndex = i - maxLen + 1;
                    }
                }
            }
        }
        String s = "";
        for (int i = startIndex; i < startIndex + maxLen; i++) {
            s += c1[i];
        }
        System.out.println(s);
    }
}